<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		Broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcastweb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0003																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla security
defined('_JEXEC') or die;
$samdb = $this->samdb;

$page = JRequest::getVar('jsm_hidden_pagenum', 0);
$limit = JRequest::getVar('jsm_row_limit', 20);
$start = $page * $limit;
$cat_view = $this->settings->request->category_view;
$songtype = $this->settings->request->songtype;
$search_data = JRequest::getVar('jsm_hidden_searchdata', '');
$search_type = JRequest::getVar('jsm_hidden_searchtype', '');
if($search_type == 'letter'){
	if($search_data == 'nolet' or $search_data == ''){
		$gosearch = '%';
	} else{
		$gosearch = $search_data.'%';
	}
	$query = "	SELECT S.ID, S.artist, S.title, S.rating
				FROM songlist S, categorylist C
				WHERE (S.artist LIKE '".$gosearch."')
				AND C.categoryID IN(".$cat_view.")
				AND S.songtype IN(".$songtype.")
				AND S.ID = C.songID
				ORDER BY S.artist, S.title ASC
				LIMIT $start, $limit
			";
}else{
	$gosearch = '%'.$search_data.'%';
	$query = "	SELECT S.ID, S.artist, S.title, S.rating
				FROM songlist S, categorylist C
				WHERE (S.artist LIKE '".$gosearch."' OR S.title LIKE '".$gosearch."')
				AND C.categoryID IN(".$cat_view.")
				AND S.songtype IN(".$songtype.")
				AND S.ID = C.songID
				ORDER BY S.artist, S.title ASC
				LIMIT $start, $limit
			";
}
$result = $samdb->getObjectList($query);

$button_class = 0;

if($this->params->table->buttons->activate_buy == 'show'){
	$button_class = $button_class + 1;
}

if($this->params->table->buttons->activate_moreinfo == 'show'){
	$button_class = $button_class + 1;
}

if($this->params->table->buttons->activate_request == 'show'){
	$button_class = $button_class + 1;
}

//print_r($result);

if(is_array($result)): ?>
	<table class="jsm_table">
		<thead>
			<tr>
				<th><?php echo JText::_('COM_JOOSAM_VIEW_LIST_TITLE'); ?></th>
				<th><?php echo JText::_('COM_JOOSAM_VIEW_LIST_ARTIST'); ?></th><?php
				if($this->params->table->rating == 'yes'): ?>
				<th><?php echo JText::_('COM_JOOSAM_VIEW_LIST_RATING'); ?></th><?php
				endif; ?>
				<th><th>
			</th>
		</thead>
		<tbody><?php
			foreach($result as $r => $item):
				$cclass = $r % 2;
				$artist = utf8_encode($item->artist);
				$title = utf8_encode($item->title); ?>
				<tr class="jsm_listrow jsm_row<?php echo $cclass; ?>">
					<td class="jsm_tableTitle">
						<?php echo $title; ?>
					</td>
					<td class="jsm_tableArtist">
						<?php echo $artist; ?>
					</td><?php
					if($this->params->table->rating == 'yes'): ?>
						<td class="jsm_ranking">
							<?php echo $this->getdata->rankStars($item->rating); ?>
						</td><?php
					endif; ?>
					<td class="jsm_buttontd_<?php echo $button_class; ?>"><?php
						if($this->params->table->buttons->activate_buy == 'show'){
							$songid = $item->ID;
							echo $this->getdata->jsm_buybutton($artist, $title, $songid);							
						}
						if($this->params->table->buttons->activate_moreinfo == 'show'): ?> <button class="jsm_button" onclick="return joosam.gosong('<?php echo $item->ID; ?>');"><?php echo JText::_('COM_JOOSAM_VIEW_LIST_MOREINFO'); ?></button> <?php endif;
						if($this->params->table->buttons->activate_request == 'show'): ?> <button class="jsm_button" onclick="return joosam.gorequest('<?php echo $item->ID; ?>');"><?php echo JText::_('COM_JOOSAM_REQUEST'); ?></button> <?php endif; ?>
					</td>
				</tr><?php
			endforeach; ?>
		</tbody>
		<tfoot>
			<tr><?php
				if($this->params->table->rating == 'yes'){
					$colspan = '4';
				} else{ $colspan = '3'; } ?>
				<td colspan="<?php echo $colspan; ?>">
					<?php echo $this->getdata->pagenation('songlist'); ?>
				</td>
			</tr>
		</tfoot>
	</table><?php
else: ?>
	<div class="jsm_warning">
		<?php
			if($cat_view == 'none'): ?>
				<span><?php echo JText::_('There are no categories available for public view at this moment.'); ?></span><?php
			elseif($search_data == 'nolet'): ?>
				<span><?php echo JText::_('COM_JOOSAM_VIEW_LIST_NOSONGFOUND'); ?></span>
			<?php
			else: ?>
				<span><?php echo JText::_('COM_JOOSAM_VIEW_LIST_NOSONGFOUNDTHISLETTER').' - '.$search_data; ?></span><?php
			endif; ?>
	</div><?php
endif; ?>
</form>